using System;
using System.Collections.Generic;
using System.Text;

namespace Acms.AcmsControls
{
    public abstract class TemplateLoaderPage : TemplatePage
    {
        protected override void OnPreInit(EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["AcmsTemplatePath"]))
            {
                templateUrl = Request.QueryString["AcmsTemplatePath"];
            }

            if (!string.IsNullOrEmpty(Request.QueryString["AcmsMasterPagePath"]))
            {
                this.MasterPageFile = Request.QueryString["AcmsMasterPagePath"];
            }

            if (!string.IsNullOrEmpty(Request.QueryString["AcmsTheme"]))
            {
                this.Theme = Request.QueryString["AcmsTheme"];
            }

            base.OnPreInit(e);
        }

        private string templateUrl;
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            EnsureChildControls();
        }

        protected override void CreateChildControls()
        {
            TemplateLoaderControl tmp = GetLoaderControl();
            tmp.PostId = PostId;
            tmp.PageTemplateUrl = templateUrl;
        }

        protected abstract TemplateLoaderControl GetLoaderControl();


    }
}
